package com.zego.wawaji.ui.Fragment.user;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.zego.wawaji.R;
import com.zego.wawaji.base.module.ModuleMgr;
import com.zego.wawaji.base.observer.MsgMgr;
import com.zego.wawaji.base.observer.MsgType;
import com.zego.wawaji.base.observer.PObserver;
import com.zego.wawaji.ui.Fragment.BaseFragment;
import com.zego.wawaji.ui.center.user.UserCenterFoot;
import com.zego.wawaji.ui.center.user.UserCenterHead;

/**
 * Created by Su on 2018/1/18.
 */
public class UserFragment extends BaseFragment implements PObserver {
    private UserCenterHead head;
    private UserCenterFoot foot;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        setContentView(R.layout.activity_user);
        initView();
        return getContentView();
    }

    private void initView() {
        LinearLayout container = (LinearLayout) findViewById(R.id.container);
        ModuleMgr.getCenterMgr().reqMyInfo(null);

        head = new UserCenterHead(getActivity());
        container.addView(head.getContentView());

        foot = new UserCenterFoot(getActivity());
        container.addView(foot.getContentView());
        MsgMgr.getInstance().attach(this);
    }

    public void refresh() {
        head.refresh();
        foot.refreshView();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        MsgMgr.getInstance().detach(this);
    }

    @Override
    public void onMessage(String key, Object value) {
        switch (key) {
            case MsgType.MT_MyInfo_Change:
                refresh();
                break;
        }
    }
}
